package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize, Long userId) {
        //1.设置分页参数
        Page<BlackList> page = new Page<>(pageNum, pageSize);

        //2.创建条件查询对象-userId
        LambdaQueryWrapper<BlackList> qw = new LambdaQueryWrapper<>();
        qw.eq(BlackList::getUserId,userId);

        //3.调用mapper.selectPage(..)
        blackListMapper.selectPage(page,qw);

        //4.封装pageBeanVo返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public void deleteByUserIdAndBlackId(Long userId, Long blackId) {
        //1.创建条件查询对象
        LambdaQueryWrapper<BlackList> qw = new LambdaQueryWrapper<>();

        //2.添加俩个条件
        qw.eq(BlackList::getUserId,userId).eq(BlackList::getBlackUserId,blackId);

        //3.调用mapper删除
        blackListMapper.delete(qw);
    }
}
